// pages/mine/order/purchase_detail.js
var App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_id: '',
    order_time: '',
    goodsList: [],
    totalAmount: 0,//合计金额
    paymentWay:'',
    paymentYue:'无',
    paymentDiscount:'无',
    vipPrice:'0.00'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getOrderDetail(options.order_no)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //back
  backLastPage: function () {
    wx.navigateBack({
      delta: 1
    })
  },
  //获取订单详情
  getOrderDetail: function (id) {
    let that = this;
    wx.request({
      url: App.data.globalAPI + '/order/usersorder/detail',
      data: {
        token: wx.getStorageSync('token'),
        order_no: id,
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        if (res.data.error == 0) {
          let data = res.data.data;
          that.setData({
            order_id: data.order_no,
            order_time: data.order_time,
            goodsList: data.goods,
            totalAmount: data.price,//合计金额
            paymentWay: data.pay_type,
            paymentYue: data.money_pay,
            paymentDiscount: parseFloat(data.coupon_price).toFixed(2),
            vipPrice: parseFloat(data.buy_vip_price).toFixed(2)
          })

        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 800
          })
        }
      }
    })
  }
})